package wu_wei;

/**
 * @DESCRIPER:队列先进先出
 * @AUTHOR:伍炜
 * @PHONE:15399846320
 * @EMIAL:1973503577@qq.COM
 * @DATE: 2021-01-23 17:04
 * @PARAMDESCRIPER:
 * @OUTPARAMDESCRIPER:
 */
public class WU_WEI_23_TH_Q2 {
    private Object[] data;//定义一个队列数组
    private int front;//队头
    private int rear;//队尾
    private int maxSize = 10;
    public WU_WEI_23_TH_Q2(){
        data = new Object[maxSize];//初始化数组
        front = rear = 0;

    }

    // 判断队列是否为满
    public Boolean isFull(){
        return (rear+1)%maxSize == front;
    }

    // 判断队列是否为空
    public Boolean isEmpty(){
        return rear == front;
    }

    public int EnQueue(Object data){
        if(isFull()){//判断是否队满
            return 0;
        }

        this.data[rear] = data;//将数据加入队尾
        rear = (rear+1)%maxSize;//队尾加一
        return 1;
    }

    public Object DeQueue(){
        if(isEmpty()){//判断是否为空
            return 0;
        }
        Object x = data[front];//获取当前数据
        front = (front+1)%maxSize;//队头加一
        return x;//返回数据
    }


    public Object GetHead(){
        if(isEmpty()){//判断是否为空
            return 0;
        }
        return data[front];//返回队头
    }

    public static void main(String args[]){
        WU_WEI_23_TH_Q2 w = new WU_WEI_23_TH_Q2();
        w.EnQueue("1");//入队
        w.EnQueue("2");//入队
        System.out.println(w.isEmpty());//判断是否为空
        System.out.println(w.isFull());//判断是否为满
        System.out.println(w.GetHead());//获取队头
        System.out.println(w.DeQueue());//出队
        System.out.println(w.DeQueue());//出队


    }



}
